package com.example.demo6.demos.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(bufferedReader.readLine());
        int[] db = new int[n];
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = bufferedReader.readLine();
        }
        for (int i = n - 1; i >= 0; i--){
            String[] split = s[i].split(" ");
            for (int j = 0; j < split.length; j++) {
                if (i == n - 1) db[j] = Integer.parseInt(split[j]);
                else {
                    int max = Math.max(db[j],db[j+1]);
                    db[j] = max + Integer.parseInt(split[j]);
                }
            }
        }
        System.out.println(db[0]);
    }
}
